package mysql

import (
	"gorm.io/gorm"
)

type House struct {
	//在 MySQL 建含的房源表
	gorm.Model
	HouseName    string `gorm:"type:varchar(30);comment:房源名称"`
	Address      string `gorm:"type:varchar(50);not null;comment:地址"`
	HouseType    string `gorm:"type:char(35);comment:房源类型"`
	HouseFloor   string `gorm:"type:char(10);comment:房源楼层"`
	Price        int64  `gorm:"type:int;comment:价格"`
	HouseArea    int64  `gorm:"type:int;comment:面积"`
	HouseCover   string `gorm:"type:varchar(300);not null;comment:房源封面"`
	HouseStatus  int64  `gorm:"type:tinyint(1);default:1;comment:房源状态:1:待出售,2:上架,3:下架"`
	HouseExamine int64  `gorm:"type:tinyint(1);default:1;comment:房源审核:1:待审核,2:审核通过,3:审核不通过"`
}

func (h *House) Create() error {
	return Db.Create(&h).Error
}
func (h *House) HouseGetInfo(houseId int) error {
	return Db.Where("id = ?", houseId).Limit(1).Find(&h).Error
}
func (h *House) UpdateHouseExamine(houseId int64) error {
	return Db.Model(&House{}).Where("id = ?", houseId).Updates(House{
		HouseStatus:  h.HouseStatus,
		HouseExamine: h.HouseExamine,
	}).Limit(1).Find(&h).Error
}
